#!/usr/bin/python

import wx
import wx.stc as stc

FILLER='\nclass MainPanel(wx.Panel):\n\n\tdef __init__(me,parent):\n\t\twx.Panel.__init__(me,parent)\n\t\t\n\t\tme.text=wx.stc.StyledTextCtrl(me)\n\t\t\n\t\tsz=wx.BoxSizer(wx.VERTICAL)\n\t\t\n\t\tme.SetSizer(sz)\n\t\t\n\t\tsz.Add(me.text,1,wx.EXPAND)\n\t\tme.SetAutoLayout(True)\n\t\t\n\t\tme.text.AddText(FILLER)\n\n\t\t\nclass MainFrame(wx.Frame):\n\n\tdef __init__(me):\n\t\t\t\n\t\twx.Frame.__init__(me,parent=None)\n\t\tMainPanel(parent=me)\n\t\t\n\napp = wx.PySimpleApp()\nframe = MainFrame()\nframe.Show()\nframe.Centre()\napp.MainLoop()\n'

import math

settings={}
settings['mode.keywords'] = "and assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while yield"
settings['text.caret_foreground']=wx.BLUE
if wx.Platform == '__WXMSW__':
    settings['text.faces'] = { 'times': 'Times New Roman',
              'mono' : 'Courier New',
              'helv' : 'Arial',
              'other': 'Comic Sans MS',
              'size' : 10,
              'size2': 8,
             }
elif wx.Platform == '__WXMAC__':
    settings['text.faces']= { 'times': 'Times New Roman',
              'mono' : 'Andale Mono',
              'helv' : 'Monaco',
              'other': 'Comic Sans MS',
              'size' : 14,
              'size2': 12,
             }
else:
    settings['text.faces'] = { 'times': 'Times',
              'mono' : 'Courier',
              'helv' : 'Helvetica',
              'other': 'new century schoolbook',
              'size' : 12,
              'size2': 10,
             }

def configure_stc_styles(tx):
	# adopted from the wxPython example
	tx.SetLexer(stc.STC_LEX_PYTHON)
	tx.SetKeyWords(0, settings['mode.keywords'])
	
	tx.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d,back:#DDDDDD" % settings['text.faces'])

	tx.StyleClearAll()
	
	# Global default styles for all languages
	tx.StyleSetSpec(stc.STC_STYLE_DEFAULT,     "face:%(helv)s,size:%(size)d,back:#DDDDDD" % settings['text.faces'])
	tx.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % settings['text.faces'])
	tx.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % settings['text.faces'])
	tx.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,  "fore:#FFFFFF,back:#0000FF,bold")
	tx.StyleSetSpec(stc.STC_STYLE_BRACEBAD,    "fore:#000000,back:#FF0000,bold")

	# Python styles
	# Default 
	tx.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % settings['text.faces'])
	# Comments
	tx.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % settings['text.faces'])
	# Number
	tx.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % settings['text.faces'])
	# String
	tx.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % settings['text.faces'])
	# Single quoted string
	tx.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % settings['text.faces'])
	# Keyword
	tx.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % settings['text.faces'])
	# Triple quotes
	tx.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % settings['text.faces'])
	# Triple double quotes
	tx.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % settings['text.faces'])
	# Class name definition
	tx.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % settings['text.faces'])
	# Function or method name definition
	tx.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % settings['text.faces'])
	# Operators
	tx.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % settings['text.faces'])
	# Identifiers
	tx.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % settings['text.faces'])
	# Comment-blocks
	tx.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % settings['text.faces'])
	# End of line where string is not closed
	tx.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % settings['text.faces'])

	tx.SetCaretForeground(settings['text.caret_foreground'])
	
	

	
class MainPanel(wx.Panel):

	def __init__(me,parent):
		wx.Panel.__init__(me,parent)
		
		me.text=wx.stc.StyledTextCtrl(me)
		
		sz=wx.BoxSizer(wx.VERTICAL)
		
		me.SetSizer(sz)
		
		sz.Add(me.text,1,wx.EXPAND)
		me.SetAutoLayout(True)
		
		me.Bind(wx.stc.EVT_STC_MODIFIED, me.OnTextModified)
		
		me.text.AddText(FILLER)
		
		configure_stc_styles(me.text)

	def OnTextModified(me,e):
		pass
		
class MainFrame(wx.Frame):

	def __init__(me):
			
		wx.Frame.__init__(me,parent=None)
		me.panel=MainPanel(parent=me)
		
		mb=wx.MenuBar()
		me.SetMenuBar(mb)
		m=wx.Menu()
		mb.Append(m,"&Menu")
		id=wx.NewId()
		m.Append(id,'Do Something')
		me.Bind(wx.EVT_MENU,me.OnMenuDoSomething,id=id)
		
		me.toggle=True
		
	def OnMenuDoSomething(me,e):
		me.toggle=not me.toggle
		
		

app = wx.PySimpleApp()
frame = MainFrame()
frame.Show()
frame.Centre()
app.MainLoop()